using Microsoft.Extensions.DependencyInjection;
using MauiApp.Services;

namespace MauiApp
{
    public partial class App : Application
    {
        // 静态的ServiceProvider，便于在整个应用程序中访问服务
        public static IServiceProvider ServiceProvider { get; private set; }
        
        // 静态全局用户信息
        public static string CurrentUsername { get; set; } = "default_user";
        public static string CurrentUserId { get; set; } = "0"; // 使用可转换为整数的默认值
        
        // 添加一个方法来打印当前用户信息（用于调试）
        public static void LogCurrentUserInfo(string source)
        {
            LogHelper.Debug($"[App] 来自 {source} 的用户信息: Username='{CurrentUsername}', UserId='{CurrentUserId}'");
        }
        
        public App()
        {
            InitializeComponent();
            
            // 初始化MauiApp并获取ServiceProvider
            var mauiApp = MauiProgram.CreateMauiApp();
            ServiceProvider = mauiApp.Services;
        }

        protected override Window CreateWindow(IActivationState? activationState)
        {
            return new Window(new AppShell());
        }
    }
}